
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Modal · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="monitor.html" />
    
    
    <link rel="prev" href="mobile recommendation.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    前端进阶
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Grid System.html">
            
                <a href="Grid System.html">
            
                    
                    Grid System
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="Handwritten signature.html">
            
                <a href="Handwritten signature.html">
            
                    
                    Handwritten Signature
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Mobile Soft Keyboard.html">
            
                <a href="Mobile Soft Keyboard.html">
            
                    
                    Mobile Soft Keyboard
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="authentication.html">
            
                <a href="authentication.html">
            
                    
                    Authentication
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    Code
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" >
            
                <span>
            
                    
                    Four Operations
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="control loading.html">
            
                <a href="control loading.html">
            
                    
                    Control Loading
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="downfile.html">
            
                <a href="downfile.html">
            
                    
                    Downfile
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="dynamic-routing.html">
            
                <a href="dynamic-routing.html">
            
                    
                    Dynamic Routing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="ecs.html">
            
                <a href="ecs.html">
            
                    
                    Ecs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="engineering.html">
            
                <a href="engineering.html">
            
                    
                    Engineering
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="eslint-vscode-format.html">
            
                <a href="eslint-vscode-format.html">
            
                    
                    Eslint Vscode Format
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="eventloop.html">
            
                <a href="eventloop.html">
            
                    
                    Eventloop
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="four-operations-1.html">
            
                <a href="four-operations-1.html">
            
                    
                    Four Operations 1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="four-operations-2.html">
            
                <a href="four-operations-2.html">
            
                    
                    Four Operations 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="four-operations-3.html">
            
                <a href="four-operations-3.html">
            
                    
                    Four Operations 3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="four-operations-4.html">
            
                <a href="four-operations-4.html">
            
                    
                    Four Operations 4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="front end summary.html">
            
                <a href="front end summary.html">
            
                    
                    Front End Summary
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="git commit style.html">
            
                <a href="git commit style.html">
            
                    
                    Git Commit Style
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="git-commands.html">
            
                <a href="git-commands.html">
            
                    
                    Git Commands
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="high-quality-code.html">
            
                <a href="high-quality-code.html">
            
                    
                    High Quality Code
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="history.html">
            
                <a href="history.html">
            
                    
                    History
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="html-tag.html">
            
                <a href="html-tag.html">
            
                    
                    Html Tag
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="http-https-http2.html">
            
                <a href="http-https-http2.html">
            
                    
                    Http Https Http2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="ignore log.html">
            
                <a href="ignore log.html">
            
                    
                    Ignore Log
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.27" >
            
                <span>
            
                    
                    Imgs
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="javascript-optimization.html">
            
                <a href="javascript-optimization.html">
            
                    
                    Javascript Optimization
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29" data-path="local application.html">
            
                <a href="local application.html">
            
                    
                    Local Application
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30" data-path="locality.html">
            
                <a href="locality.html">
            
                    
                    Locality
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.31" data-path="loop-unrolling.html">
            
                <a href="loop-unrolling.html">
            
                    
                    Loop Unrolling
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.32" data-path="mobile recommendation.html">
            
                <a href="mobile recommendation.html">
            
                    
                    Mobile Recommendation
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.33" data-path="modal.html">
            
                <a href="modal.html">
            
                    
                    Modal
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.34" data-path="monitor.html">
            
                <a href="monitor.html">
            
                    
                    Monitor
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.35" data-path="performance.html">
            
                <a href="performance.html">
            
                    
                    Performance
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.36" data-path="print-talbe.html">
            
                <a href="print-talbe.html">
            
                    
                    Print Talbe
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.37" data-path="promise.html">
            
                <a href="promise.html">
            
                    
                    Promise
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.38" data-path="teaching.html">
            
                <a href="teaching.html">
            
                    
                    Teaching
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.39" data-path="vue refresh.html">
            
                <a href="vue refresh.html">
            
                    
                    Vue Refresh
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.40" data-path="vue-page-not-refresh.html">
            
                <a href="vue-page-not-refresh.html">
            
                    
                    Vue Page Not Refresh
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.41" data-path="why-learn-theory.html">
            
                <a href="why-learn-theory.html">
            
                    
                    Why Learn Theory
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Modal</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5F00;&#x53D1;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;-vue-&#x5F39;&#x7A97;&#x7EC4;&#x4EF6;">&#x5F00;&#x53D1;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684; Vue &#x5F39;&#x7A97;&#x7EC4;&#x4EF6;</h1>
<p>&#x4E00;&#x4E2A;&#x5F39;&#x7A97;&#x7EC4;&#x4EF6;&#x901A;&#x5E38;&#x5305;&#x542B;&#x4E24;&#x4E2A;&#x90E8;&#x5206;&#xFF0C;&#x5206;&#x522B;&#x662F;&#x906E;&#x7F69;&#x5C42;&#x548C;&#x5185;&#x5BB9;&#x5C42;&#x3002;</p>
<p>&#x906E;&#x7F69;&#x5C42;&#x662F;&#x80CC;&#x666F;&#x5C42;&#xFF0C;&#x4E00;&#x822C;&#x662F;&#x534A;&#x900F;&#x660E;&#x6216;&#x4E0D;&#x900F;&#x660E;&#x7684;&#x9ED1;&#x8272;&#x3002;</p>
<p>&#x5185;&#x5BB9;&#x5C42;&#x662F;&#x653E;&#x6211;&#x4EEC;&#x8981;&#x5C55;&#x793A;&#x7684;&#x5185;&#x5BB9;&#x7684;&#x5BB9;&#x5668;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-bg&quot;</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;show&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-container&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-header&quot;</span>&gt;</span>
                {{ title }}
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-main&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">slot</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-footer&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;hideModal&quot;</span>&gt;</span>&#x53D6;&#x6D88;<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;submit&quot;</span>&gt;</span>&#x786E;&#x8BA4;<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
</code></pre>
<p>&#x73B0;&#x5728;&#x5F39;&#x7A97;&#x7EC4;&#x4EF6;&#x7684;&#x7ED3;&#x6784;&#x5DF2;&#x7ECF;&#x642D;&#x5EFA;&#x51FA;&#x6765;&#x4E86;&#x3002;</p>
<ul>
<li>&#x7C7B; <code>modal-bg</code>: &#x906E;&#x7F69;&#x5C42;</li>
<li>&#x7C7B; <code>modal-container</code>: &#x5185;&#x5BB9;&#x5C42;&#x5BB9;&#x5668;</li>
<li>&#x7C7B; <code>modal-header</code>: &#x5185;&#x5BB9;&#x5C42;&#x5934;&#x90E8;</li>
<li>&#x7C7B; <code>modal-main</code>: &#x5185;&#x5BB9;&#x5C42;&#x4E3B;&#x4F53;&#x90E8;&#x5206;&#xFF08;&#x7528;&#x6765;&#x5C55;&#x793A;&#x5185;&#x5BB9;&#xFF09;</li>
<li>&#x7C7B; <code>modal-footer</code>: &#x5185;&#x5BB9;&#x5C42;&#x811A;&#x90E8;</li>
<li>&#x5C5E;&#x6027; <code>v-show</code>: &#x63A7;&#x5236;&#x5F39;&#x7A97;&#x7684;&#x5C55;&#x793A;&#x4E0E;&#x5173;&#x95ED;</li>
<li>&#x5C5E;&#x6027; <code>title</code>: &#x6807;&#x9898;</li>
<li>&#x65B9;&#x6CD5; <code>hideModal</code>: &#x70B9;&#x51FB;&#x53D6;&#x6D88;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;</li>
<li>&#x65B9;&#x6CD5; <code>submit</code>: &#x70B9;&#x51FB;&#x786E;&#x8BA4;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;</li>
<li>&#x63D2;&#x69FD; <code>slot</code>: &#x7528;&#x6765;&#x5C55;&#x793A;&#x5185;&#x5BB9;</li>
</ul>
<p>&#x5B9A;&#x4E49;&#x5B8C; HTML &#x7ED3;&#x6784;&#xFF0C;&#x8FD8;&#x5F97;&#x5B9A;&#x4E49;&#x7EC4;&#x4EF6;&#x7684; <code>props</code> &#x5C5E;&#x6027;&#xFF0C;&#x7528;&#x6765;&#x63A5;&#x6536;&#x7236;&#x7EC4;&#x4EF6;&#x7684;&#x4F20;&#x53C2;&#xFF0C;&#x4EE5;&#x65B9;&#x4FBF;&#x5728;&#x7236;&#x7EC4;&#x4EF6;&#x901A;&#x8FC7;&#x5C5E;&#x6027;&#x6765;&#x63A7;&#x5236;&#x5F39;&#x7A97;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    name: <span class="hljs-string">&apos;modal&apos;</span>,
    props: {
        show: {
            type: <span class="hljs-built_in">Boolean</span>,
            <span class="hljs-keyword">default</span>: <span class="hljs-literal">false</span>
        },
        title: {
            type: <span class="hljs-built_in">String</span>,
            <span class="hljs-keyword">default</span>: <span class="hljs-string">&apos;&apos;</span>
        },
    },
    methods: {
        hideModal() {
            <span class="hljs-keyword">this</span>.$emit(<span class="hljs-string">&apos;hideModal&apos;</span>)
        },

        submit() {
            <span class="hljs-keyword">this</span>.$emit(<span class="hljs-string">&apos;submit&apos;</span>)
        },
    }
}
</code></pre>
<p>&#x4ECE;&#x4E0A;&#x8FF0;&#x4EE3;&#x7801;&#x53EF;&#x77E5;&#xFF0C;&#x7EC4;&#x4EF6;&#x53EA;&#x6709;&#x4E24;&#x4E2A; <code>prop</code> &#x5C5E;&#x6027;&#xFF0C;&#x5206;&#x522B;&#x662F; <code>show</code>&#xFF08;&#x63A7;&#x5236;&#x5F39;&#x7A97;&#x5C55;&#x793A;&#x4E0E;&#x5173;&#x95ED;&#xFF09;&#x548C; <code>title</code>&#xFF08;&#x5F39;&#x7A97;&#x6807;&#x9898;&#xFF09;&#x3002;
&#x53E6;&#x5916;&#x8FD8;&#x6709;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x5206;&#x522B;&#x662F;&#x70B9;&#x51FB;&#x53D6;&#x6D88;&#x548C;&#x786E;&#x8BA4;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x5B83;&#x4EEC;&#x7684;&#x4F5C;&#x7528;&#x662F;&#x89E6;&#x53D1;&#x5BF9;&#x5E94;&#x7684;&#x4E8B;&#x4EF6;&#x3002;
&#x5230;&#x8FD9;&#x91CC;&#xFF0C;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x5F39;&#x7A97;&#x7EC4;&#x4EF6;&#x5DF2;&#x7ECF;&#x5B8C;&#x6210;&#x4E86;&#xFF08;&#x6837;&#x5F0F;&#x540E;&#x9762;&#x518D;&#x8BF4;&#xFF09;&#x3002;</p>
<h2 id="&#x5982;&#x4F55;&#x8C03;&#x7528;">&#x5982;&#x4F55;&#x8C03;&#x7528;</h2>
<p>&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6;&#x5199;&#x5B8C;&#x4E86;&#xFF0C;&#x8981;&#x600E;&#x4E48;&#x8C03;&#x7528;&#x5462;&#xFF1F;</p>
<p>&#x5047;&#x8BBE;&#x8FD9;&#x4E2A;&#x7EC4;&#x4EF6;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x4E3A; <code>Modal.vue</code>&#xFF0C;&#x6211;&#x4EEC;&#x5728;&#x7236;&#x7EC4;&#x4EF6;&#x91CC;&#x8FD9;&#x6837;&#x8C03;&#x7528; &#xFF08;&#x5047;&#x8BBE;&#x7236;&#x7EC4;&#x4EF6;&#x548C;&#x5F39;&#x7A97;&#x7EC4;&#x4EF6;&#x5728;&#x540C;&#x4E00;&#x6587;&#x4EF6;&#x5939;&#x4E0B;&#xFF09;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">Modal</span> <span class="hljs-attr">:show</span>=<span class="hljs-string">&quot;show&quot;</span> <span class="hljs-attr">:title</span>=<span class="hljs-string">&quot;title&quot;</span> @<span class="hljs-attr">hideModal</span>=<span class="hljs-string">&quot;hideModal&quot;</span> @<span class="hljs-attr">submit</span>=<span class="hljs-string">&quot;submit&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>&#x8FD9;&#x91CC;&#x653E;&#x5F39;&#x7A97;&#x7684;&#x5185;&#x5BB9;<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">Modal</span>&gt;</span>
</code></pre>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> Modal <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./Modal.vue&apos;</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    data() {
      <span class="hljs-keyword">return</span> {
        title: <span class="hljs-string">&apos;&#x5F39;&#x7A97;&#x6807;&#x9898;&apos;</span>,
        show: <span class="hljs-literal">true</span>,
      }
    },
    components: {
        Modal
    },
    methods: {
        hideModal() {
            <span class="hljs-comment">// &#x53D6;&#x6D88;&#x5F39;&#x7A97;&#x56DE;&#x8C03;</span>
            <span class="hljs-keyword">this</span>.show = <span class="hljs-literal">false</span>
        },

        submit() {
            <span class="hljs-comment">// &#x786E;&#x8BA4;&#x5F39;&#x7A97;&#x56DE;&#x8C03;</span>
            <span class="hljs-keyword">this</span>.show = <span class="hljs-literal">false</span>
        }
    }
}
</code></pre>
<p>&#x628A;&#x5B50;&#x7EC4;&#x4EF6;&#x8981;&#x6C42;&#x7684;&#x4E24;&#x4E2A;&#x5C5E;&#x6027;&#x548C;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x90FD;&#x5199;&#x4E0A;&#xFF0C;&#x73B0;&#x5728;&#x6765;&#x770B;&#x770B;&#x8FD9;&#x4E2A;&#x5F39;&#x7A97;&#x7684;&#x6548;&#x679C;&#x3002;
<img src="https://img-blog.csdnimg.cn/20190614144642191.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3E0MTEwMjAzODI=,size_16,color_FFFFFF,t_70" alt="img">
&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x5F39;&#x7A97;&#x7EC4;&#x4EF6;&#x5C31;&#x8FD9;&#x6837;&#x5B8C;&#x6210;&#x4E86;&#x3002;</p>
<h2 id="&#x6539;&#x8FDB;">&#x6539;&#x8FDB;</h2>
<h3 id="&#x6837;&#x5F0F;">&#x6837;&#x5F0F;</h3>
<p>&#x73B0;&#x5728;&#x5E02;&#x9762;&#x4E0A;&#x7684; UI &#x5E93;&#x7279;&#x522B;&#x591A;&#xFF0C;&#x6240;&#x4EE5;&#x4E00;&#x4E9B;&#x901A;&#x7528;&#x7684;&#x7EC4;&#x4EF6;&#x6837;&#x5F0F;&#x4E0D;&#x5EFA;&#x8BAE;&#x81EA;&#x5DF1;&#x5199;&#xFF0C;&#x76F4;&#x63A5;&#x7528;&#x73B0;&#x6210;&#x7684;&#x5C31;&#x597D;&#x3002;&#x5728;&#x8FD9;&#x4E2A;&#x7EC4;&#x4EF6;&#x4E0A;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; element-ui&#xFF0C;&#x6539;&#x9020;&#x540E;&#x53D8;&#x6210;&#x8FD9;&#x6837;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-bg&quot;</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;show&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-container&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-header&quot;</span>&gt;</span>
                {{ title }}
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-main&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">slot</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-footer&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span> <span class="hljs-attr">round</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;hideModal&quot;</span>&gt;</span>&#x53D6;&#x6D88;<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;primary&quot;</span> <span class="hljs-attr">round</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;submit&quot;</span>&gt;</span>&#x786E;&#x8BA4;<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
</code></pre>
<p>&#x55EF;... &#x770B;&#x8D77;&#x6765;&#x53EA;&#x6709;&#x4E24;&#x4E2A;&#x6309;&#x94AE;&#x53D8;&#x5316;&#x4E86;&#xFF0C;&#x4E0D;&#x8FC7;&#x6CA1;&#x5173;&#x7CFB;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x5185;&#x5BB9;&#x90E8;&#x5206;&#x80AF;&#x5B9A;&#x8FD8;&#x6709;&#x7528;&#x5F97;&#x4E0A;&#x7684;&#x65F6;&#x5019;&#x3002;</p>
<h3 id="&#x529F;&#x80FD;">&#x529F;&#x80FD;</h3>
<p>&#x770B;&#x8D77;&#x6765;&#x8FD9;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x5F39;&#x7A97;&#x7EC4;&#x4EF6;&#x771F;&#x7684;&#x662F;&#x975E;&#x5E38;&#x7B80;&#x5355;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x6B64;&#x57FA;&#x7840;&#x4E0A;&#x9002;&#x5F53;&#x7684;&#x589E;&#x52A0;&#x4E00;&#x4E9B;&#x529F;&#x80FD;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;&#x62D6;&#x62FD;&#x3002;</p>
<p>&#x4E00;&#x4E2A;&#x5F39;&#x7A97;&#x7EC4;&#x4EF6;&#x7684;&#x62D6;&#x62FD;&#x4E00;&#x822C;&#x901A;&#x8FC7;&#x4E09;&#x4E2A;&#x4E8B;&#x4EF6;&#x6765;&#x63A7;&#x5236;&#xFF0C;&#x5206;&#x522B;&#x662F; <code>mousedown</code>&#x3001;<code>mousemove</code>&#x3001;<code>mouseup</code>&#x3002;</p>
<ul>
<li><code>mousedown</code> &#x7528;&#x6765;&#x83B7;&#x53D6;&#x9F20;&#x6807;&#x70B9;&#x51FB;&#x65F6;&#x5F39;&#x7A97;&#x7684;&#x5750;&#x6807;</li>
<li><code>mousemove</code> &#x7528;&#x6765;&#x8BA1;&#x7B97;&#x9F20;&#x6807;&#x79FB;&#x52A8;&#x65F6;&#x5F39;&#x7A97;&#x7684;&#x5750;&#x6807;</li>
<li><code>mouseup</code> &#x53D6;&#x6D88;&#x5F39;&#x7A97;&#x7684;&#x79FB;&#x52A8;</li>
</ul>
<p>&#x5148;&#x6765;&#x770B;&#x4EE3;&#x7801;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-bg&quot;</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;show&quot;</span> @<span class="hljs-attr">mousemove</span>=<span class="hljs-string">&quot;modalMove&quot;</span> @<span class="hljs-attr">mouseup</span>=<span class="hljs-string">&quot;cancelMove&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-container&quot;</span> <span class="hljs-attr">:class</span>=<span class="hljs-string">&quot;position&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-header&quot;</span> @<span class="hljs-attr">mousedown</span>=<span class="hljs-string">&quot;setStartingPoint&quot;</span>&gt;</span>
                {{ title }}
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-main&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">slot</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-footer&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span> <span class="hljs-attr">round</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;hideModal&quot;</span>&gt;</span>&#x53D6;&#x6D88;<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;primary&quot;</span> <span class="hljs-attr">round</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;submit&quot;</span>&gt;</span>&#x786E;&#x8BA4;<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
</code></pre>
<p>&#x5728;&#x5F39;&#x7A97;&#x4E0A;&#x589E;&#x52A0;&#x4E86;&#x4E09;&#x4E2A;&#x4E8B;&#x4EF6; <code>mousedown</code>&#x3001;<code>mousemove</code>&#x3001;<code>mouseup</code>&#xFF0C;&#x7528;&#x6765;&#x63A7;&#x5236;&#x5F39;&#x7A97;&#x79FB;&#x52A8;&#xFF08;&#x70B9;&#x51FB;&#x5F39;&#x7A97;&#x5934;&#x90E8;&#x8FDB;&#x884C;&#x62D6;&#x62FD;&#xFF09;&#x3002;</p>
<pre><code class="lang-js">    data() {
        <span class="hljs-keyword">return</span> {
            x: <span class="hljs-number">0</span>, <span class="hljs-comment">// &#x5F39;&#x7A97; X &#x5750;&#x6807;</span>
            y: <span class="hljs-number">0</span>, <span class="hljs-comment">// &#x5F39;&#x7A97; Y &#x5750;&#x6807;</span>
            node: <span class="hljs-literal">null</span>, <span class="hljs-comment">// &#x5F39;&#x7A97;&#x5143;&#x7D20;</span>
            isCanMove: <span class="hljs-literal">false</span> <span class="hljs-comment">// &#x662F;&#x5426;&#x80FD;&#x62D6;&#x52A8;&#x5F39;&#x7A97;</span>
        }
    },
    mounted() {
        <span class="hljs-comment">// &#x5C06;&#x5F39;&#x7A97;&#x5143;&#x7D20;&#x8D4B;&#x503C;&#x7ED9; node</span>
        <span class="hljs-keyword">this</span>.node = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;.modal-container&apos;</span>)
    },
    setStartingPoint(e) {
        <span class="hljs-keyword">this</span>.x = e.clientX - <span class="hljs-keyword">this</span>.node.offsetLeft
        <span class="hljs-keyword">this</span>.y = e.clientY - <span class="hljs-keyword">this</span>.node.offsetTop
        <span class="hljs-keyword">this</span>.isCanMove = <span class="hljs-literal">true</span>
    },

    modalMove(e) {
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.isCanMove) {
            <span class="hljs-keyword">this</span>.node.style.left = e.clientX - <span class="hljs-keyword">this</span>.x + <span class="hljs-string">&apos;px&apos;</span>
            <span class="hljs-keyword">this</span>.node.style.top = e.clientY - <span class="hljs-keyword">this</span>.y + <span class="hljs-string">&apos;px&apos;</span>
        } 
    },

    cancelMove() {
        <span class="hljs-keyword">this</span>.isCanMove = <span class="hljs-literal">false</span>
    }
</code></pre>
<p>&#x901A;&#x8FC7;&#x8FD9;&#x4E9B;&#x65B0;&#x589E;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x8FD9;&#x4E2A;&#x5F39;&#x7A97;&#x5C31;&#x5177;&#x6709;&#x4E86;&#x62D6;&#x62FD;&#x7684;&#x529F;&#x80FD;&#x3002;</p>
<p>&#x6700;&#x540E;&#x9644;&#x4E0A;&#x8FD9;&#x4E2A;&#x5F39;&#x7A97;&#x7EC4;&#x4EF6;&#x7684;&#x5B8C;&#x6574;&#x4EE3;&#x7801;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-bg&quot;</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;show&quot;</span> @<span class="hljs-attr">mousemove</span>=<span class="hljs-string">&quot;modalMove&quot;</span> @<span class="hljs-attr">mouseup</span>=<span class="hljs-string">&quot;cancelMove&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-container&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-header&quot;</span> @<span class="hljs-attr">mousedown</span>=<span class="hljs-string">&quot;setStartingPoint&quot;</span>&gt;</span>
                {{ title }}
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-main&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">slot</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-footer&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span> <span class="hljs-attr">round</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;hideModal&quot;</span>&gt;</span>&#x53D6;&#x6D88;<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;primary&quot;</span> <span class="hljs-attr">round</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;submit&quot;</span>&gt;</span>&#x786E;&#x8BA4;<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
</code></pre>
<pre><code class="lang-js">&lt;script&gt;
export default {
    name: &apos;modal&apos;,
    props: {
        show: {
            type: Boolean,
            default: false
        },
        title: {
            type: String,
            default: &apos;&apos;
        },
    },
    data() {
        return {
            x: 0,
            y: 0,
            node: null,
            isCanMove: false
        }
    },
    mounted() {
        this.node = document.querySelector(&apos;.modal-container&apos;)
    },
    methods: {
        hideModal() {
            this.$emit(&apos;hideModal&apos;)
        },

        submit() {
            this.$emit(&apos;submit&apos;)
        },

        setStartingPoint(e) {
            this.x = e.clientX - this.node.offsetLeft
            this.y = e.clientY - this.node.offsetTop
            this.isCanMove = true
        },

        modalMove(e) {
            if (this.isCanMove) {
                this.node.style.left = e.clientX - this.x + &apos;px&apos;
                this.node.style.top = e.clientY - this.y + &apos;px&apos;
            } 
        },

        cancelMove() {
            this.isCanMove = false
        }
    }
}
&lt;/script&gt;
</code></pre>
<pre><code class="lang-css">&lt;style scoped&gt;
.modal-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.5);
    z-index: 10;
}
.modal-container {
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}
.modal-header {
    height: 56px;
    background: #409EFF;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: move;
}
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 57px;
    border-top: 1px solid #ddd;
}
.modal-footer button {
    width: 100px;
}
.modal-main {
    padding: 15px 40px;
}
&lt;/style&gt;
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="mobile recommendation.html" class="navigation navigation-prev " aria-label="Previous page: Mobile Recommendation">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="monitor.html" class="navigation navigation-next " aria-label="Next page: Monitor">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Modal","level":"1.33","depth":1,"next":{"title":"Monitor","level":"1.34","depth":1,"path":"前端进阶/monitor.md","ref":"前端进阶/monitor.md","articles":[]},"previous":{"title":"Mobile Recommendation","level":"1.32","depth":1,"path":"前端进阶/mobile recommendation.md","ref":"前端进阶/mobile recommendation.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["summary","livereload"],"pluginsConfig":{"summary":{},"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"前端进阶/modal.md","mtime":"2021-02-15T12:04:36.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-03-24T08:50:55.666Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

